home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / rcvhsn.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  5KB  |  174 lines

  1.  /*
  2.  *
  3.  *                        RCVHS
  4.  *                Receive records from HS
  5.  *   This function receives records from the HS and places it
  6.  *   into the input queue to the RCB.
  7.  *
  8.  *   Records received from the HS make the list "RCB -> first_in".
  9.  *   The text and other info from that list  will be moved to buff.
  10.  *
  11.  *   INPUT :  - count for received characters; pointer to RCB,
  12.  *              pointer to type field, data buffer.
  13.  *
  14.  *   OUTPUT:  - return code as follow:
  15.  *            0 - OK;
  16.  *            2 - system error in HS or in here.
  17.  *
  18.  *  CopyRight 1995. Nicholas Poljakov all rights reserved.
  19.  *
  20.  */
  21. #include <stdio.h>
  22. #include <state1.h>
  23. #include <rcb.h>
  24. #include <prefix.h>
  25. #include <malloc.h>
  26. #include <string.h>
  27. int sk_r_wt(void *);
  28. int SendBlock(void *, void *);
  29. int setrc(void *, void *);
  30. int sendhsf(void *);
  31. int sendhs(void *);
  32. int sendbm(void *, void *);
  33. int sendat(void *);
  34. int rtsend(void *);
  35. unsigned long rmfmh5(void *, void *);
  36. int recwait(void *);
  37. int rcvru(void *, void *);
  38. int ralloc(void *, void *);
  39. int psrm(int, void *, void *);
  40. int ps_conv(int, void *);
  41. int proterr(void *, unsigned long);
  42. int preptrcv(void *, void *);
  43. int post_rcb(void *);
  44. struct repass *postopen(void *);
  45. int phsrec(void *);
  46. int pfmh5(void *);
  47. int opndst(void *);
  48. int obtsess(void *, unsigned char);
  49. int Lrf_handler(void *);
  50. int get_sess(void *, void *);
  51. int get_attr(void *);
  52. int fsm_error(unsigned char, void *);
  53. int fsm_conv(unsigned char, unsigned char, void *);
  54. int flush (void *);
  55. int dcp(void *);
  56. int dealloc(void *);
  57. int crtp(void *);
  58. int conv(void *);
  59. int chkparm(void *, void *);
  60. int check_end(unsigned int, void *);
  61. struct rqb *call_appl(void *);
  62. int buffmng(unsigned char, void *, void *, void *, unsigned, unsigned char, unsigned);
  63. unsigned long attltck(void *);
  64. unsigned long attacheck(void *);
  65. char *cgetmem(int, int);
  66. int sendhsf(void *);
  67. int opndst(void *);
  68. int alloc_rcb(void *, void *);
  69. int allocate(void *);
  70. int clsdst(void *);
  71.  
  72. int rcvhs(p_cnt, p_rcb, p_type, buff)
  73. int *p_cnt;  /* on input : max. length;
  74.               * on output: data length */
  75. struct rcb *p_rcb;
  76. unsigned int *p_type; /* type of record (DFC code) */
  77. char *buff;  /* data buffer */
  78. {
  79.     struct prefix *p_prf;
  80.     struct prefix *t_prf;
  81.     int i;
  82.     int j;
  83.     int lim;
  84.     char *p;
  85.     char *p1;
  86.  
  87. #if OS_TYPE == 1
  88. /*********  Trace facility **********/
  89. unsigned int rtype;   /* type of record */
  90. unsigned int pnum;    /* point number */
  91. char pname[8];        /* name of module */
  92. char *drec;       /* record for dump */
  93. int  lenr;            /* record length */
  94.  
  95. rtype = INPROC;
  96. strcpy(pname, "rcvhs");
  97. pnum = 1;
  98. drec = p_rcb;
  99. lenr = sizeof(struct rcb);
  100. gtf(rtype, pname, pnum, drec, lenr);
  101. /***********************************/
  102. #endif
  103.  
  104.  
  105.     if (p_rcb -> hsps == No) {
  106.         goto rcv_exit_1;
  107.     }
  108.     if ((p_prf = p_rcb -> first_in) == NULL) {
  109.         goto rcv_exit_1;
  110.     }
  111.     if (*p_cnt <= 0) {
  112.         lim = MAX_RU;
  113.     }
  114.     else
  115.         lim = *p_cnt;
  116.     i = p_prf -> lt_text;
  117. #if OS_TYPE == 1 /* Unix System V */
  118. printf("LUPS...rcvhs...len = %d, lim = %d\n", i, lim);
  119. #endif
  120.     if (i > lim) {
  121.        /* buff is full; insert new element in the
  122.         * RCB -> first_in chain.
  123.         */
  124.         i = lim;
  125.         j = p_prf -> lt_text - i;
  126.         if ((t_prf = malloc(sizeof(struct prefix) + j)) == NULL) {
  127.             goto rcv_exit_2;
  128.         }
  129.         p = (char *)t_prf + sizeof(struct prefix);
  130.         t_prf -> next = p_prf -> next;
  131.         t_prf -> prev = p_prf;
  132.         t_prf -> text = p;
  133.         t_prf -> lt_text = j;
  134.         t_prf -> type = p_prf -> type;
  135.         p_prf -> type = Send_data;
  136.         t_prf -> dsc = p_prf -> dsc;
  137.         p_prf -> next = t_prf;
  138.         p_prf -> lt_text = i;
  139.         p1 = p_prf -> text;
  140.         p1 += i;
  141.         memcpy(p, p1, j);
  142.     }
  143.     /*
  144.      * Delete the first element from the input chain.
  145.      */
  146.  
  147.     *p_type = p_prf -> type;
  148.     *p_cnt = i;
  149.     memcpy(buff, p_prf -> text, i);
  150.  
  151.     free(p_prf -> text);
  152.     t_prf = p_prf;
  153.     p_prf = p_prf -> next;
  154.     free(t_prf);
  155.     if (p_prf != NULL) {
  156.         p_rcb -> first_in = p_prf;
  157.         p_prf -> prev = NULL;
  158.     }
  159.     else
  160.             p_rcb -> first_in = NULL;
  161.  
  162.     if (p_rcb -> first_in == NULL) {
  163.         p_rcb -> hsps = No;
  164.     }
  165.            fsm_error(RESET, p_rcb);
  166.                    return(0);
  167.      rcv_exit_1 :
  168.            fsm_error(CONV_FAIL_SON, p_rcb);
  169.                    return (1);
  170.      rcv_exit_2 :
  171.            fsm_error(Receive_error, p_rcb);
  172.                    return (2);
  173. }
  174.